# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=lua-optarg
_rockname=optarg
pkgver=0.3
pkgrel=0
pkgdesc="Simple command line option parser for Lua"
url="https://github.com/ncopa/lua-optarg"
arch="noarch"
license="MIT"
source="$pkgname-$pkgver.tar.gz::https://github.com/ncopa/lua-optarg/archive/v$pkgver.tar.gz"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_package"
	checkdepends="$checkdepends lua$_v-unit"
done

check() {
	for _v in $_luaversions; do
		msg "testing Lua $_v"
		lua$_v -e "package.path='$PWD/?.lua;'..package.path" test.lua
	done
}

package() {
	mkdir -p "$pkgdir"
}

_package() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc $lver"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_rockname/$pkgver-1"

	install -Dm644 "$builddir"/optarg.lua \
		"$subpkgdir"/usr/share/lua/$lver/optarg.lua

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="
394a0cc4055bc2bb0fdb486f4f07d319232733b639fcc95d4cf59d88d18058641b58b6cd3f56766ccd08bcf2af0dae1e11a492b80f763fb9ae8ce75673089349  lua-optarg-0.3.tar.gz
"
